home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
splib
/
splib.lzh
/
PRG
/
LHX
/
USRLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-07
|
9KB
|
440 lines
/*************************************************************************
* "usrlib.c"
*-------------------------------------------------------------------------
* By TaroPYON
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <msdos.cf>
#include <loader.h>
#include <egb.h>
#include "usrlib.h"
#include <disp.h>
#include <cnslib.h>
#include <dta.h>
#include <dialog.h>
#include <fslib.h>
#include <kyb.h>
#include <setint.h>
#include <keycode.h>
#include <event.h>
#include <sbar.h>
#include <mouse.h>
#include <moscur.h>
#include <spicon.h>
#include <egbmacro.h>
#include "usrlib.h"
#include "lh.h"
#ifdef __HIGHC__
# pragma On(Align_labels);
#endif
DTACTRL_T *DtaCtrl = NULL;
static CONST char RECODENAME_DSPCTRL[] = "$DspCtrl";
static CONST char RECODENAME_MAINARG[] = "$MainArg";
DLG_T *LhxDlg = NULL;
CNS_T *LhxCns = NULL;
EVT_T *LhxEvt = NULL;
SBAR_T *LhxSbV = NULL;
#define CNS_XS (80)
#define CNS_YS (24)
#define DLG_XS ( 4 + CNS_XS* 6 + 2+16+4)
#define DLG_YS (20+4 + CNS_YS*12 + 4)
static int LhxCh;
static UINT LhxEc;
#define BREAK_CHECK() { \
LhxCh = EVT_getkey( &LhxEc ); \
if ( LhxCh == 3 || (LhxEc&0xFF14) == (KA_C|KA_BIT_CTRL) ) \
userbreak(0); \
}
#define MAIN_EVT_CANCEL (9999)
static PLT_RGB PltDat[16] =
{
/* G R B */
{ 0, 0, 0}, /* C_BALCK */
{ 0, 0, 0}, /* C_BLUE or C_THROUGH */
{ 7, 7, 8}, /* C_RED */
{12,12,13}, /* C_MAGENTA */
{ 6, 5, 7}, /* C_GREEN */
{ 8, 7, 9}, /* C_CYAN */
{10, 9,11}, /* C_YELLOW */
{11,11,12}, /* C_WHITE */
{ 5, 5, 6}, /* C_HBALCK */
{ 0, 0,11}, /* C_HBLUE */
{ 0,11, 0}, /* C_HRED */
{ 0,11,11}, /* C_HMAGENTA */
{11, 0, 0}, /* C_HGEEN */
{11, 0,11}, /* C_HCYAN */
{11,11, 0}, /* C_HYELLOW */
{14,14,15} /* C_HWHITE */
};
/* #define _LHX_DEBUG */
#ifdef _LHX_DEBUG
static int _dspPosY = 0;
# define DPUTS(s) wrtstr((s),WRTPAGE(1),WRTADR(32,28+(_dspPosY++)*18),WRTCOL(C_HGREEN),WRTCOL(0),16)
#else
# define DPUTS(s)
#endif
void LHX_dspFlush(void)
{
LhxSbV->top = LhxCns->dspPos.lnD;
LhxSbV->dsp = LhxCns->dspYm;
LhxSbV->min = 0;
LhxSbV->max = LhxCns->linMaxD ? LhxCns->linMaxD - 1 : 0;
SBAR_Vredraw(LhxSbV);
}
/*************************************************************************
* â_âCâìâAâOò\Īè╓Éö
*************************************************************************/
static void dspFunc( DLG_T *dlg )
{
int evtPos = 0;
int x1 = dlg->fr.x0;
int y1 = dlg->fr.y0;
int x2 = x1 + dlg->fr.xs - 1;
// int y2 = y1 + dlg->fr.ys - 1;
int cx1, cy1, cx2, cy2;
extern char title[];
boxfHol( x1+2, y1+2, x2-2, y1+2+18, PSET, C_WHITE, C_HWHITE, C_DARK );
DSP_str( x1+4, y1+4, C_MBLACK, C_WHITE, 16, "%s", title );
/* [EXIT]â{â^âô --------------------------------------------*/
{
CONST int x = x2 - 18;
CONST int y = y1 + 3;
EGB_writeMode( EgbPtr, OPAQUE );
EGB_paintMode( EgbPtr, 0x022);
EGB_color( EgbPtr, 0, C_DARK );
EGB_color( EgbPtr, 1, C_WHITE );
_EGB_PUTBLOCKCOLOR(0, x, y, x+15, y+15, getds(), _icn16x16_closeBtn );
boxHol( x, y, x+15, y+15, PSET, C_HWHITE, C_DARK );
_EVT_SETMOS( LhxEvt, evtPos++, MAIN_EVT_CANCEL, MOSEVT_BTN, BTN_LEFT,
x, y, x+15, y+15, 0, NULL );
}
/* â_âCâAâìâOê┌ô«ùp ----------------------------------------*/
_EVT_SETMOS( LhxEvt, evtPos++, 0, MOSEVT_NOACT|MOSEVT_QUICK, BTN_LEFT,
x1+2, y1+2, x2-2, y1+2+18, DLG_defMoveFunc, dlg );
/* âRâôâ\ü[âïù╠êµ */
cx1 = x1+4;
cy1 = y1+24;
cx2 = x1 + 4 + CNS_XS* 6 - 1;
cy2 = y1 +24 + CNS_YS*12 - 1;
box( cx1-1, cy1-1, cx2+1, cy2+1, PSET, C_WHITE );
box( cx1-2, cy1-2, cx2+2, cy2+2, PSET, C_DARK );
CNS_changeScnSize( LhxCns, cx1, cy1, cx2, cy2 );
CNS_flush( LhxCns, ERR, ERR);
/* âXâNâìü[âïâoü[ */
SBAR_Vdsp( LhxSbV, cx2+5, cy1, 16, cy2-cy1+1 );
LHX_dspFlush();
}
/*************************************************************************
* âXâNâìü[âïâoü[âTü[ârâXè╓Éö
*************************************************************************/
static int funcSbarV( int evtNo, SBAR_T *sbV )
{
CNS_T *cns = LhxCns;
if ( cns->linMaxD < cns->dspYm )
{
sbV->top = 0;
return (0);
} else if ( sbV->top > cns->homeY )
sbV->top = cns->homeY;
switch( evtNo )
{
case SBEVT_SLIDE:
MOS_DEC();
CNS_jump( cns, sbV->top );
MOS_INC();
break;
case SBEVT_INC:
if ( sbV->top <= cns->homeY )
{
MOS_DEC();
CNS_nextLine( cns, 1 );
MOS_INC();
}
break;
case SBEVT_DEC:
MOS_DEC();
CNS_prevLine( cns, 1 );
MOS_INC();
break;
}
return (0);
}
static void hit_any_key(void)
{
int ch;
UINT ec;
LHX_puts("\n**** Hit any key *****\n");
MOS_curType(MOSCUR_NORMAL);
MOS_CON();
for(;;)
{
int ret;
LHX_dspFlush();
if ( (ret = EVT_chk(LhxEvt,EVTIGN_KEY)) >= 0 )
{
if ( ret == MAIN_EVT_CANCEL )
break;
} else
{
ch = EVT_getkey(&ec);
if ( ch != 0xFFFF || (ec & 0xFF00) != 0xFF00 )
{ ec &= 0xFF14;
switch( ec )
{
case KA_UP:
case KA_W|KA_BIT_CTRL:
case KA_PREV:
MOS_DEC();
CNS_prevLine( LhxCns, 1 );
MOS_INC();
break;
case KA_DOWN:
case KA_Z|KA_BIT_CTRL:
case KA_NEXT:
MOS_DEC();
CNS_nextLine( LhxCns, 1 );
MOS_INC();
break;
case KA_UP|KA_BIT_SHIFT:
case KA_R|KA_BIT_CTRL:
MOS_DEC();
CNS_prevLine( LhxCns, LhxCns->dspYm );
MOS_INC();
break;
case KA_DOWN|KA_BIT_SHIFT:
case KA_C|KA_BIT_CTRL:
MOS_DEC();
CNS_nextLine( LhxCns, LhxCns->dspYm );
MOS_INC();
break;
default:
goto LOOP_EXIT;
}
} else
EVT_idl();
}
}
LOOP_EXIT:
return;
}
int USYS_init( int *argc, char **argv[], int _argc, char *_argv[] )
{
DTARECODE_T *dsp_recode = NULL;
DTARECODE_T *arg_recode = NULL;
DSPCTRL *dsp = NULL;
*argc = _argc;
*argv = _argv;
if ( DTA_isAtPcl() )
{
char *args = "LHx";
DPUTS("DTA_openCheck()");
if ( (DtaCtrl = DTA_openCheck()) != NULL )
{
if ( (dsp_recode = DTA_openRecode( DtaCtrl, RECODENAME_DSPCTRL)) != NULL )
{ /* ò\ĪâVâXâeâÇé╠Åεò±éáéΦ */
DPUTS("Get DspCtrl");
dsp = dsp_recode->ptr;
}
if ( (arg_recode = DTA_openRecode( DtaCtrl, RECODENAME_MAINARG)) != NULL )
{ /* âpâëâüü[â^é╠ÄwÆΦéáéΦ */
DPUTS("Get argc/argv");
args = arg_recode->ptr;
}
}
if ( (*argc = FS_argSet( args, argv )) < 1 )
return (ERR);
}
set_ctrl_c();
set24h();
/* ò\ĪâVâXâeâÇÅëè·ë╗ */
if ( DSP_pcl_sysInit( dsp ) )
return (ERR);
if ( dsp == NULL )
DSP_setPlt(PltDat);
DSP_set_defFnt( FNTYPE_USR1 );
GetFnt12Ptr(0);
KBF_sysInit();
/* âCâxâôâgùp */
LhxEvt = EVT_alloc(NULL,8);
LhxSbV = SBAR_Vopen(LhxEvt, funcSbarV, NULL );
LhxCns = CNS_open();
/* â_âCâAâìâOâIü[âvâô */
LhxDlg = DLG_open( DLGPOS_CENTER_OF_SCN, DLGPOS_CENTER_OF_SCN,
DLG_XS, DLG_YS, C_DLGBASE, dspFunc, NULL );
if ( LhxEvt == NULL || LhxSbV == NULL || LhxDlg == NULL || LhxCns == NULL )
return (ERR);
LhxCns->page = DspCtrl.writePage;
LhxSbV->attr |= (SBATT_SLIDEQUICK | SBATT_MAXADJUST);
DLG_dsp(LhxDlg);
return (NORMAL);
}
void USYS_term( int errLevel )
{
hit_any_key();
if ( LhxCns )
{
CNS_close( LhxCns );
LhxCns = NULL;
}
if ( LhxDlg )
{ DLG_close( LhxDlg );
LhxDlg = NULL;
}
if ( DtaCtrl )
{
if ( DtaCtrl->head )
DtaCtrl->head->ret = errLevel;
DTA_flush( DtaCtrl );
DTA_freeCtrl( DtaCtrl );
DtaCtrl = NULL;
}
KBF_sysEnd();
DSP_pcl_sysEnd();
reset24h();
pcl_exit(0);
exit( errLevel );
}
int LHX_putc( int ch )
{
BREAK_CHECK();
ch &= 0xFF;
if ( ch == '\n' )
{ CNS_puts( LhxCns,"\r\n");
LHX_dspFlush();
} else
CNS_putc( LhxCns, ch );
return (ch);
}
int LHX_fputc( int ch, FILE